<template>
  <BlueBackground :title="'我的收藏'">
    <div class="collect-box">
      <ShopItem
        :dataObj="dataObj"
        :itemStyle="itemStyle"
        :boxStyle="boxStyle"
        :isDel="true"
        @delData="delDataObj"
      ></ShopItem>
      <van-empty
        v-if="dataObj.length === 0"
        description="你的收藏空空如也，快去收藏吧"
      />
    </div>
  </BlueBackground>
</template>

<script>
import BlueBackground from "../components/BlueBackground.vue";
import ShopItem from "../components/ShopItem.vue";
export default {
  name: "Collect",
  data() {
    return {
      tokenString: sessionStorage.getItem("userToken"),
      appkey: "U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
      dataObj: [],
      //   shopIndex: null,
      itemStyle: {
        width: "calc(100% / 3 )",
        borderRadius: 0,
        padding: "10px 0",
        margin: 0,
      },
      boxStyle: {
        padding: 0,
        borderRadius: "10px",
        backgroundColor: "#fff",
      },
    };
  },
  methods: {
    getDataObj() {
      let appkey = this.appkey;
      let tokenString = this.tokenString;
      if (tokenString) {
        this.axios({
          method: "get",
          url: "http://www.kangliuyong.com:10002/findAllLike",
          params: {
            appkey,
            tokenString,
          },
        })
          .then((res) => {
            this.dataObj = res.data.result;
          })
          .catch((err) => {});
      }
    },
    delDataObj(index) {
      let tokenString = sessionStorage.getItem("userToken");
      let appkey = this.appkey;
      let pid = this.dataObj[index].pid;
      let data = `appkey=${appkey}&pid=${pid}&tokenString=${tokenString}`;
      this.axios({
        method: "post",
        url: "http://www.kangliuyong.com:10002/notlike",
        data,
      })
        .then((res) => {
          this.dataObj.splice(index, 1);
        })
        .catch((err) => {});
    },
  },
  created() {
    this.getDataObj();
  },
  components: {
    BlueBackground,
    ShopItem,
  },
};
</script>

<style lang="less" scoped>
.collect-box {
  padding: 0 20px;
}
</style>